/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Merlion.MRP.entity;

import Merlion.SCM.entity.MaterialEntity;
import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Temporal;

/**
 *
 * @author Indra
 */
@Entity
public class IndividualWeeklyMaterialRequirementEntity implements Serializable {

    @Id
    private String id;
    private Integer yearInt;
    private Integer monthInt;
    private Integer weekOfMonth;
    @ManyToOne
    private MaterialEntity material;
    @OneToMany
    private Collection<WeeklyMaterialRequirementEntity> weeklyProductRequirements;
    private int requiredAmount;
    private int plannedOrder;
    private int plannedReceipt;
    private int inHandInventory; //by the end of the week
    private String unit;
    private boolean purchased;
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date availableBy;
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date requestedOn;
    private String status;
    private String remarks;
    private int leadTime; // in weeks
    
    public IndividualWeeklyMaterialRequirementEntity() {
    }

    public IndividualWeeklyMaterialRequirementEntity(WeeklyMaterialRequirementEntity wmr, MaterialEntity material, int quantity) {
        String idString = "IMR" + material.getId().toString() + "-Y" + wmr.getYearInt() + "M" + wmr.getMonthInt() + "W" + wmr.getWeekOfMonth();
        this.id = idString;
        this.yearInt = wmr.getYearInt();
        this.monthInt = wmr.getMonthInt();
        this.weekOfMonth = wmr.getWeekOfMonth();
        this.material = material;
        this.requiredAmount = quantity;
        this.leadTime = material.getLeadTime();
        this.purchased = false;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public Date getAvailableBy() {
        return availableBy;
    }

    public void setAvailableBy(Date availableBy) {
        this.availableBy = availableBy;
    }

    public int getLeadTime() {
        return leadTime;
    }

    public void setLeadTime(int leadTime) {
        this.leadTime = leadTime;
    }

    public String getRemarks() {
        return remarks;
    }

    public void setRemarks(String remarks) {
        this.remarks = remarks;
    }

    public Date getRequestedOn() {
        return requestedOn;
    }

    public void setRequestedOn(Date requestedOn) {
        this.requestedOn = requestedOn;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public int getInHandInventory() {
        return inHandInventory;
    }

    public void setInHandInventory(int inHandInventory) {
        this.inHandInventory = inHandInventory;
    }

    public int getPlannedReceipt() {
        return plannedReceipt;
    }

    public void setPlannedReceipt(int plannedReceipt) {
        this.plannedReceipt = plannedReceipt;
    }

    public int getPlannedOrder() {
        return plannedOrder;
    }

    public void setPlannedOrder(int plannedOrder) {
        this.plannedOrder = plannedOrder;
    }

    
    public Integer getMonthInt() {
        return monthInt;
    }

    public void setMonthInt(Integer monthInt) {
        this.monthInt = monthInt;
    }

    public Integer getWeekOfMonth() {
        return weekOfMonth;
    }

    public void setWeekOfMonth(Integer weekOfMonth) {
        this.weekOfMonth = weekOfMonth;
    }

    public Integer getYearInt() {
        return yearInt;
    }

    public void setYearInt(Integer yearInt) {
        this.yearInt = yearInt;
    }

    public boolean isPurchased() {
        return purchased;
    }

    public void setPurchased(boolean purchased) {
        this.purchased = purchased;
    }

    public MaterialEntity getMaterial() {
        return material;
    }

    public void setMaterial(MaterialEntity material) {
        this.material = material;
    }

    public Collection<WeeklyMaterialRequirementEntity> getWeeklyProductRequirements() {
        return weeklyProductRequirements;
    }

    public void setWeeklyProductRequirements(Collection<WeeklyMaterialRequirementEntity> weeklyProductRequirements) {
        this.weeklyProductRequirements = weeklyProductRequirements;
    }

    public int getRequiredAmount() {
        return requiredAmount;
    }

    public void setRequiredAmount(int requiredAmount) {
        this.requiredAmount = requiredAmount;
    }

    public String getUnit() {
        return unit;
    }

    public void setUnit(String unit) {
        this.unit = unit;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof IndividualWeeklyMaterialRequirementEntity)) {
            return false;
        }
        IndividualWeeklyMaterialRequirementEntity other = (IndividualWeeklyMaterialRequirementEntity) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "mrp.entities.MaterialRequirementWeeklyIndividual[ id=" + id + " ]";
    }
}
